/*
 * PACKAGE NAME: com.jodinfo.outmirror.api.reportrepair.controller
 * FILE    NAME: ReportRepairDaoImpl.java
 * COPYRIGHT: Copyright(c) © 2016 heroj Company Ltd. All Rights Reserved
 */ 
package com.jodinfo.outmirror.api.reportrepair.controller;

import java.math.BigInteger;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.hero.common.web.context.UserContext;
import com.hero.core.constant.SysConstant;
import com.hero.core.entity.IPlatformUser;
import com.hero.core.entity.ResponseEntity;
import com.jodinfo.outmirror.api.reportrepair.entity.ReportRepairEntity;
import com.jodinfo.outmirror.api.reportrepair.service.ReportRepairBizService;



@Controller
@RequestMapping(value = "/ReportRepairAdmin")
public class ReportRepairController  {
	
@Resource(name="reportRepairBizService")
private ReportRepairBizService ReportRepairBizService;
/**
*  list数据源
* 
* */
@RequestMapping(value = "/List")
@ResponseBody
public String ReportRepairList(ReportRepairEntity ReportRepairEntity) {
	if(ReportRepairEntity==null){
		ReportRepairEntity = new ReportRepairEntity();
		ReportRepairEntity.setPageIndex(SysConstant.DEFAULT_PAGEINDEX);
		ReportRepairEntity.setPageSize(SysConstant.DEFAULT_PAGESIZE);
	}
	ReportRepairEntity.setCurrentUser(UserContext.getUser());
	if(StringUtils.isEmpty(ReportRepairEntity.getBranchOrgId())&&StringUtils.isEmpty(ReportRepairEntity.getOfficeOrgId())){
		ReportRepairEntity.setBranchOrgId(((IPlatformUser)UserContext.getUser()).getOrgId());
		ReportRepairEntity.setOfficeOrgId(((IPlatformUser)UserContext.getUser()).getOrgId());
	}
	String str = ReportRepairBizService.queryListForPageReportRepair(ReportRepairEntity);
	return str;
}
/**
* ReportRepairEntity List页面
* 
* */
@RequestMapping(value = "/ListPage")
public ModelAndView ReportRepairListPage(ReportRepairEntity ReportRepairEntity,HttpServletRequest request) {
	
	return new ModelAndView(returnPath("ReportRepairList"));
}
/**
* ReportRepairEntity详细页 
* 
* */
@RequestMapping(value = "/EditPage")
public ModelAndView ReportRepairEditPage(ReportRepairEntity ReportRepairEntity) {
	
	return new ModelAndView(returnPath("ReportRepairAdd"));
}
/**
 * 查询ReportRepairEntity
 * 
 * */
@RequestMapping(value = "/queryByID")
public @ResponseBody String findReportRepairData(HttpServletRequest request) {
	String id = request.getParameter("id");
	ReportRepairEntity ReportRepairEntity =  ReportRepairBizService.queryById(new BigInteger(id));
	return JSON.toJSONString(ReportRepairEntity); 
}

/**
 * 保存或更新ReportRepair 
 * 
 * */
@RequestMapping(value = "/saveReportRepair")
public @ResponseBody String saveReportRepairData(@RequestBody ReportRepairEntity ReportRepairEntity) {
	ResponseEntity rs = null;
	if(ReportRepairEntity!=null){
		ReportRepairEntity.setCurrentUser(UserContext.getUser());
		if(ReportRepairEntity.getId()!=null){
			rs = ReportRepairBizService.updateReportRepair(ReportRepairEntity);
		}else{
			rs = ReportRepairBizService.addReportRepair(ReportRepairEntity);
		}
	}
	return JSON.toJSONString(rs);
}
/**
 * 导出ReportRepairEntity
 * @author weiwei
 * @date 2015-7-09  下午2:13:28
 * @return
 */
@RequestMapping(value = "/exportReportRepairExcel")
public void exportReportRepairExcel(ReportRepairEntity ReportRepairEntity,HttpServletResponse response) {
	if(ReportRepairEntity==null){
		ReportRepairEntity = new ReportRepairEntity();
	}
	ReportRepairEntity.setCurrentUser(UserContext.getUser());
	if(StringUtils.isEmpty(ReportRepairEntity.getBranchOrgId())&&StringUtils.isEmpty(ReportRepairEntity.getOfficeOrgId())){
		ReportRepairEntity.setBranchOrgId(((IPlatformUser)UserContext.getUser()).getOrgId());
		ReportRepairEntity.setOfficeOrgId(((IPlatformUser)UserContext.getUser()).getOrgId());
	}
	ReportRepairBizService.exportReportRepair(ReportRepairEntity, response);
}


 /**
 * 
 * 批量删除
 * @author weiwei
 * @date 2017年3月13日 下午2:48:57
 * @param ReportRepairEntity
 * @return
 */
@RequestMapping(value = "/batchDelReportRepair")
public @ResponseBody String batchDelReportRepair(ReportRepairEntity ReportRepairEntity) {
	ResponseEntity rs = null;
	rs = ReportRepairBizService.batchDelReportRepair(ReportRepairEntity);
	return  JSON.toJSONString(rs);
}
/**
 * 定义
 * 
 */
private final String MODULE_PATH = "/reportrepair/";

//返回路径
private String returnPath(String jspName) {
	return MODULE_PATH + jspName;
}
}
